home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / DTS.Draw / ToolPalette.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  6.5 KB  |  253 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        ToolPalette.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This file contains the code for the document procedure pointers for the DTS.Draw
  20. ** tool palette document.  The tool palette document does very little, so most of
  21. ** the document procedure pointers are set to nil.  Imaging and clicking are the
  22. ** only two methods that we need to support. */
  23.  
  24.  
  25.  
  26. /*****************************************************************************/
  27.  
  28.  
  29.  
  30. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  31. #include "App.defs.h"        /* Get various application definitions.            */
  32. #include "App.protos.h"        /* Get the prototypes for the application.        */
  33.  
  34. #ifndef __ERRORS__
  35. #include <Errors.h>
  36. #endif
  37.  
  38. #ifndef __FONTS__
  39. #include <Fonts.h>
  40. #endif
  41.  
  42. #ifndef __RESOURCES__
  43. #include <Resources.h>
  44. #endif
  45.  
  46. #ifndef __TOOLUTILS__
  47. #include <ToolUtils.h>
  48. #endif
  49.  
  50. #ifndef __TREEOBJ2__
  51. #include "TreeObj2.h"
  52. #endif
  53.  
  54. #ifndef __UTILITIES__
  55. #include "Utilities.h"
  56. #endif
  57.  
  58.  
  59. /*****************************************************************************/
  60.  
  61.  
  62.  
  63. static void        ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
  64. static OSErr    ToolImageDocument(FileRecHndl frHndl);
  65. static Rect        PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  66.  
  67.  
  68.  
  69. /*****************************************************************************/
  70. /*****************************************************************************/
  71.  
  72.  
  73.  
  74. /* Just imaging and clicking are handles by the tool palette. */
  75.  
  76. #pragma segment ToolPalette
  77. OSErr    ToolInitDocument(FileRecHndl frHndl)
  78. {
  79.     FileRecPtr    frPtr;
  80.  
  81.     frPtr = *frHndl;
  82.     frPtr->fileState.calcFrameRgnProc        = nil;
  83.     frPtr->fileState.contentClickProc        = ToolContentClick;
  84.     frPtr->fileState.contentKeyProc          = nil;
  85.     frPtr->fileState.drawFrameProc           = nil;
  86.     frPtr->fileState.freeDocumentProc        = nil;
  87.     frPtr->fileState.freeWindowProc          = nil;
  88.     frPtr->fileState.imageProc               = ToolImageDocument;
  89.     frPtr->fileState.readDocumentProc        = nil;
  90.     frPtr->fileState.readDocumentHeaderProc  = nil;
  91.     frPtr->fileState.resizeContentProc       = nil;
  92.     frPtr->fileState.scrollFrameProc         = nil;
  93.     frPtr->fileState.undoFixupProc           = nil;
  94.     frPtr->fileState.windowCursorProc        = nil;
  95.     frPtr->fileState.writeDocumentProc       = nil;
  96.     frPtr->fileState.writeDocumentHeaderProc = nil;
  97.  
  98.     return(noErr);
  99. }
  100.  
  101.  
  102.  
  103. /*****************************************************************************/
  104. /*****************************************************************************/
  105.  
  106.  
  107.  
  108. /* Find out which tool was clicked or double-clicked on. */
  109.  
  110. #pragma segment ToolPalette
  111. static void    ToolContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  112. {
  113. #pragma unused (firstClick)
  114.  
  115.     short            cnum;
  116.     ControlHandle    ctl;
  117.     MenuHandle        menu;
  118.     short            i;
  119.  
  120.     if (cnum = IsCtlEvent(window, event, &ctl, nil)) {
  121.         menu = GetMHandle(mToolPalette);
  122.         for (i = kArrowTool; i <= kPieTool; ++i) SetItemMark(menu, i, noMark);
  123.         SetItemMark(menu, cnum - rArrowIcon + 1, '0' + (*ctl)->contrlValue);
  124.     }
  125. }
  126.  
  127.  
  128.  
  129. /*****************************************************************************/
  130.  
  131.  
  132.  
  133. /* Draw the tool palette icons into the port.  If DTS.LIB..framework calls us, the
  134. ** port is already set, but we set it here so that we can call this function
  135. ** directly.  Calling it directly is desireable for certain operations, such
  136. ** as when the user clicks with a one-shot tool.  When this occurs, we revert
  137. ** back to the arrow tool.  Also, if a tool is permanently selected and the
  138. ** user clicks in a document but then doesn't grow out an object, we also revert
  139. ** to the arrow tool.  Another case is if the user selects a tool via the menu. */
  140.  
  141. #pragma segment ToolPalette
  142. static OSErr    ToolImageDocument(FileRecHndl frHndl)
  143. {
  144. #pragma unused (frHndl)
  145.  
  146.     DoDrawControls((*frHndl)->fileState.window, false);
  147.     return(noErr);
  148. }
  149.  
  150.  
  151.  
  152. /*****************************************************************************/
  153. /*****************************************************************************/
  154.  
  155.  
  156.  
  157. #pragma segment ToolPalette
  158. Rect    PlaceToolWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo)
  159. {
  160. #pragma unused (relatedWindow, sizeInfo)
  161.  
  162.     Rect    scnRct, cntRct;
  163.     short    dx, dy;
  164.  
  165.     scnRct = GetMainScreenRect();
  166.     cntRct = GetWindowContentRect(window);
  167.  
  168.     dx = cntRct.right  - cntRct.left;
  169.     dy = cntRct.bottom - cntRct.top;
  170.  
  171.     cntRct.right  = scnRct.right - 5;
  172.     cntRct.top    = scnRct.top   + 33;
  173.     cntRct.left   = cntRct.right - dx;
  174.     cntRct.bottom = cntRct.top + dy;
  175.  
  176.     MoveWindow(window, cntRct.left, cntRct.top, false);
  177.     return(cntRct);
  178. }
  179.  
  180.  
  181.  
  182. /*****************************************************************************/
  183.  
  184.  
  185.  
  186. /* Tool palette set tool function. */
  187.  
  188. #pragma segment ToolPalette
  189. void    SetPaletteTool(short tool)
  190. {
  191.     MenuHandle        menu;
  192.     WindowPtr        toolWind;
  193.     ControlHandle    ctl;
  194.     short            i;
  195.  
  196.     if (!(toolWind = GetNextWindow(nil, kToolFileType))) return;
  197.  
  198.     menu = GetMHandle(mToolPalette);
  199.     for (ctl = nil, i = 1; ctl = CCIconNext(toolWind, ctl, 1, true); ++i) {
  200.         if (Ctl2CNum(ctl) - rArrowIcon == tool) {
  201.             SetCtlValue(ctl, 1);
  202.             SetItemMark(menu, i, '1');
  203.         }
  204.         else {
  205.             SetCtlValue(ctl, 0);
  206.             SetItemMark(menu, i, noMark);
  207.         }
  208.     }
  209. }
  210.  
  211.  
  212.  
  213. /*****************************************************************************/
  214.  
  215.  
  216.  
  217. #pragma segment ToolPalette
  218. short    GetTool(void)
  219. {
  220.     WindowPtr        toolWind;
  221.     ControlHandle    ctl;
  222.  
  223.     if (!(toolWind = GetNextWindow(nil, kToolFileType))) return(false);
  224.  
  225.     for (ctl = nil; ctl = CCIconNext(toolWind, ctl, 1, true);)
  226.         if ((*ctl)->contrlValue) break;
  227.  
  228.     return(Ctl2CNum(ctl) - rArrowIcon);
  229. }
  230.  
  231.  
  232.  
  233. /*****************************************************************************/
  234.  
  235.  
  236.  
  237. #pragma segment ToolPalette
  238. Boolean    GetToolPersistence(void)
  239. {
  240.     WindowPtr        toolWind;
  241.     ControlHandle    ctl;
  242.  
  243.     if (!(toolWind = GetNextWindow(nil, kToolFileType))) return(false);
  244.  
  245.     for (ctl = nil; ctl = CCIconNext(toolWind, ctl, 1, true);)
  246.         if ((*ctl)->contrlValue == 2) return(true);
  247.  
  248.     return(false);
  249. }
  250.  
  251.  
  252.  
  253.